<a href="http://github.com/angular/angular.js/tree/v1.2.2/src/ng/filter/limitTo.js#L3" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/ng/filter/limitTo.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">limitTo</code>
<div><span class="hint">filter in module <code ng:non-bindable="">ng</code>
</span>
</div>
</h1>
<div><h2 id="description">Description</h2>
<div class="description"><div class="ng-filter-page ng-filter-limitto-page"><p>Creates a new array or string containing only a specified number of elements. The elements
are taken from either the beginning or the end of the source array or string, as specified by
the value and sign (positive or negative) of <code>limit</code>.</p>
</div></div>
<h2 id="usage">Usage</h2>
<div class="usage"><pre class="prettyprint linenums">filter:limitTo(input, limit);</pre>
<h4 id="usage_parameters">Parameters</h4><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>input</td><td><a href="" class="label type-hint type-hint-array">Array</a><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="ng-filter-page ng-filter-limitto-page"><p>Source array or string to be limited.</p>
</div></td></tr><tr><td>limit</td><td><a href="" class="label type-hint type-hint-string">string</a><a href="" class="label type-hint type-hint-number">number</a></td><td><div class="ng-filter-page ng-filter-limitto-page"><p>The length of the returned array or string. If the <code>limit</code> number 
is positive, <code>limit</code> number of items from the beginning of the source array/string are copied.
If the number is negative, <code>limit</code> number  of items from the end of the source array/string 
are copied. The <code>limit</code> will be trimmed if it exceeds <code>array.length</code></p>
</div></td></tr></tbody></table><h4 id="usage_returns">Returns</h4><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-array">Array|string</a></td><td><div class="ng-filter-page ng-filter-limitto-page"><p>A new sub-array or substring of length <code>limit</code> or less if input array
had less than <code>limit</code> elements.</p>
</div></td></tr></table></div>
<h2 id="example">Example</h2>
<div class="example"><div class="ng-filter-page ng-filter-limitto-page"><h4 id="example_source">Source</h4>
<div source-edit="" source-edit-deps="angular.js script.js" source-edit-html="index.html-136" source-edit-css="" source-edit-js="script.js-135" source-edit-json="" source-edit-unit="" source-edit-scenario="scenario.js-137"></div>
<div class="tabbable"><div class="tab-pane" title="index.html">
<pre class="prettyprint linenums" ng-set-text="index.html-136" ng-html-wrap=" angular.js script.js"></pre>
<script type="text/ng-template" id="index.html-136">
  
  <div ng-controller="Ctrl">
    Limit {{numbers}} to: <input type="integer" ng-model="numLimit">
    <p>Output numbers: {{ numbers | limitTo:numLimit }}</p>
    Limit {{letters}} to: <input type="integer" ng-model="letterLimit">
    <p>Output letters: {{ letters | limitTo:letterLimit }}</p>
  </div>
</script>
</div>
<div class="tab-pane" title="script.js">
<pre class="prettyprint linenums" ng-set-text="script.js-135"></pre>
<script type="text/ng-template" id="script.js-135">
    function Ctrl($scope) {
      $scope.numbers = [1,2,3,4,5,6,7,8,9];
      $scope.letters = "abcdefghi";
      $scope.numLimit = 3;
      $scope.letterLimit = 3;
    }
  </script>
</div>
<div class="tab-pane" title="End to end test">
<pre class="prettyprint linenums" ng-set-text="scenario.js-137"></pre>
<script type="text/ng-template" id="scenario.js-137">
  it('should limit the number array to first three items', function() {
    expect(element('.doc-example-live input[ng-model=numLimit]').val()).toBe('3');
    expect(element('.doc-example-live input[ng-model=letterLimit]').val()).toBe('3');
    expect(binding('numbers | limitTo:numLimit')).toEqual('[1,2,3]');
    expect(binding('letters | limitTo:letterLimit')).toEqual('abc');
  });

  it('should update the output when -3 is entered', function() {
    input('numLimit').enter(-3);
    input('letterLimit').enter(-3);
    expect(binding('numbers | limitTo:numLimit')).toEqual('[7,8,9]');
    expect(binding('letters | limitTo:letterLimit')).toEqual('ghi');
  });

  it('should not exceed the maximum size of input array', function() {
    input('numLimit').enter(100);
    input('letterLimit').enter(100);
    expect(binding('numbers | limitTo:numLimit')).toEqual('[1,2,3,4,5,6,7,8,9]');
    expect(binding('letters | limitTo:letterLimit')).toEqual('abcdefghi');
  });
</script>
</div>
</div><h4 id="example_demo">Demo</h4>
<div class="well doc-example-live animate-container" ng-embed-app="" ng-set-html="index.html-136" ng-eval-javascript="script.js-135"></div>
</div></div>
</div>
